//
//  LeaseListViewController.m
//  PersonalProjects
//
//  Created by 王家骏 on 15/9/13.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "LeaseListViewController.h"
#import "YPKStatisticsRequest.h"
#import "LeaseListModel.h"
#import "LeaseListTableViewCell.h"

@interface LeaseListViewController ()
//@property (nonatomic, strong) LeaseListTableViewCell *leaseListTableViewCell;
@property (nonatomic, strong) NSMutableArray *leaseListMidelArray;

@property (nonatomic, assign) BOOL isLoadMore;
@end

@implementation LeaseListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.leaseListMidelArray = [[NSMutableArray alloc] init];
    // Do any additional setup after loading the view.
    
    self.leaseListTableView.delegate = self;
    self.leaseListTableView.dataSource = self;
    
    [self requsetLeaseListDataWithTotalCount:0
                                    endCount:19
                              successRefresh:^{
                                  [self.leaseListTableView reloadData];
                                  
                              } failureRefresh:^{
                                  [self.leaseListTableView reloadData];
                                  
                              }];
}

- (void)requsetLeaseListDataWithTotalCount:(NSInteger)startCount
                                  endCount:(NSInteger)endCount
                            successRefresh:(void(^)())successRefresh
                            failureRefresh:(void(^)())failureRefresh {
    [YPKStatisticsRequest getLeaseListWithUserId:@"593"
                                         startNo:[NSString stringWithFormat:@"%ld",(long)startCount]
                                           endNo:[NSString stringWithFormat:@"%ld",(long)endCount]
                                         success:^(id responseObject) {
                                             NSLog(@"%@", responseObject);
                                             if (![responseObject isKindOfClass:[NSNull class]] && responseObject != nil) {
                                                 if ([responseObject[@"code"] integerValue] == 1001 && responseObject[@"result"] != nil && ![responseObject[@"result"] isKindOfClass:[NSNull class]]) {
                                                     NSArray *listArray = responseObject[@"result"][@"list_data"];
                                                     if (listArray.count != 0 && ![listArray isKindOfClass:[NSNull class]] && listArray != nil) {
//                                                         if (_isLoadMore == YES) {
//                                                             
//                                                         } else {
//                                                             [self.leaseListMidelArray removeAllObjects];
//                                                         }
                                                         [self.leaseListMidelArray removeAllObjects];
                                                     }
                                                     for (NSDictionary *dic in listArray) {
                                                         LeaseListModel *leaseListModel = [[LeaseListModel alloc] initWithDictionary:dic];
                                                         [self.leaseListMidelArray addObject:leaseListModel];
                                                     }
                                                 }
                                             }
                                             successRefresh();
                                         } failure:^(NSError *error) {
                                             DLog(@"error = %@",error);
                                             failureRefresh();
                                         }];
}

#pragma mark - TableView
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return 1;
//}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.leaseListMidelArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // 取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    LeaseListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LeaseListTableViewCell" forIndexPath:indexPath];
//    UIStoryboard *PaymentStryBoard = [UIStoryboard storyboardWithName:@"Payment" bundle:nil];
//    self.leaseListTableViewCell = [PaymentStryBoard instantiateViewControllerWithIdentifier:@"LeaseListTableViewCell"];
    cell.leaseListCellModel = self.leaseListMidelArray[indexPath.row];
    return cell;
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/



@end
